# Contributor: Clayton Craft <clayton@craftyguy.net>
# Contributor: Thomas Böhler <witcher@wiredspace.de>
# Maintainer: Clayton Craft <clayton@craftyguy.net>
pkgname=goimapnotify
pkgver=2.3.10
pkgrel=0
pkgdesc="execute scripts on IMAP mailbox changes using IDLE, golang version"
url="https://gitlab.com/shackra/goimapnotify"
arch="all"
license="GPL-3.0-or-later"
makedepends="go"
options="net"
source="https://gitlab.com/shackra/goimapnotify/-/archive/$pkgver/goimapnotify-$pkgver.tar.gz"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	export CGO_CPPFLAGS="$CPPFLAGS"
	export CGO_CFLAGS="$CFLAGS"
	export CGO_CXXFLAGS="$CXXFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"
	export GOFLAGS="$GOFLAGS -trimpath -mod=readonly -modcacherw"

	# Fix build on riscv64
	go mod edit -replace \
		golang.org/x/sys=golang.org/x/sys@v0.0.0-20210630005230-0f9fa26af87c
	go mod download golang.org/x/sys

	go build -ldflags "-linkmode=external \"-extldflags=$LDFLAGS\""
}

check() {
	go test ./...
}

package() {
	install -Dm755 goimapnotify "$pkgdir"/usr/bin/goimapnotify
	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/"$pkgname"/LICENSE
	install -Dm644 README.md "$pkgdir"/usr/share/doc/"$pkgname"/README.md
	install -Dm644 CHANGELOG.rst "$pkgdir"/usr/share/doc/"$pkgname"/CHANGELOG.rst
}

sha512sums="
cadaba1e28c42e9ca5fd3c15a649f6eab9e9fa030a5f8c08bdf440703695fd55928553f63c983a9cb97b04a7d48d796fa6de4dcdc823f89832a48d82abe0dd4b  goimapnotify-2.3.10.tar.gz
"
